import Vue from 'vue'
import VueRouter from 'vue-router'
// import Home from '../views/home.vue'

Vue.use(VueRouter)

const routes = [

]

export function loadRoutes(router) {
  const viewCtx = require.context('../views', false, /\.vue$/)
  const views = viewCtx.keys().map(v => v.split('/')[1].replace(/\.vue$/g, ''))
  const routes = views.map(v => {
    return {
      path: `/${v}`,
      name: v,
      component: () => import(`../views/${v}.vue`)
      // component: `../views/${v}.vue`
    }
  })

  router.addRoutes(routes)
}

const router = new VueRouter({
  mode: 'history',
  // base: process.env.BASE_URL,
  base: '/vue/',
  routes
})

router.beforeEach((to, from, next) => {
  // let routes = router.getRoutes()
  // console.log(routes)

  next()
})

export default router
